﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Security.Cryptography;

namespace sqxt
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }
        public static string yhm;              //登录的用户
        string s1, s2;                      //s1密文，s2密钥，s4身份
        public static string s4;
        public string uid,pwd;
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
            SqlConnection conn = new SqlConnection(Dbconnect.s1);
            ArrayList arr = new ArrayList();
            SqlCommand com = new SqlCommand("select empcode from employee ", conn);
            conn.Open();
            SqlDataReader sdr = com.ExecuteReader();
            while (sdr.Read())
            {

                arr.Add(sdr.GetString(0));
            }
            //foreach (string s in arr)
            //{
            //    tB_uid.Items.Add(s);
            //}
            sdr.Close();
            tB_uid.Focus();
            //this.tB_uid.SelectedIndex = 0;

        }

        //private void comboBox1_TextChanged(object sender, EventArgs e)
        //{
        //    yhm = tB_uid.Text.Trim();
        //    tB_pwd.Focus();
        //}

        //static public string jm(string s1, string s2)
        //{

        //    try
        //    {
        //        byte[] DataToDecrypt = Convert.FromBase64String(s1);
        //        RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
        //        byte[] bytes_Public_Key = Convert.FromBase64String(s2);
        //        RSA.ImportCspBlob(bytes_Public_Key);
        //        byte[] bytes_Plain_Text = RSA.Decrypt(DataToDecrypt, false);
        //        UnicodeEncoding ByteConverter = new UnicodeEncoding();
        //        string str_Plain_Text = ByteConverter.GetString(bytes_Plain_Text);
        //        return str_Plain_Text;
        //    }
        //    catch (CryptographicException e)
        //    {
        //        MessageBox.Show(e.ToString());
        //        return null;
        //    }
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            #region  新的登录方式

            string temp = CheckInput();
            if (!string.IsNullOrEmpty(temp))
            {
                MessageBox.Show(temp, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                tB_uid.Focus();
                return;
            }
            this.DialogResult = DialogResult.OK;

        }
         private string CheckInput()
          {
              uid = tB_uid.Text.Trim();
              pwd = tB_pwd.Text.Trim();
            if (string.IsNullOrEmpty(uid))
                return "登陆用户不得为空！  ";
            if (string.IsNullOrEmpty(pwd))
                return "登陆密码不得为空！  ";
            //if (strUser != "1" || strPass != "1")
            //    return "登陆用户或登陆密码错误！    ";
            return string.Empty;
          }
            #endregion

        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            tB_uid.Text = "";
            tB_pwd.Text = "";
            tB_uid.Focus();
        }

        private void tB_uid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                bt_login.Focus();
        }

        private void tB_pwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
               
                tB_pwd.Focus();
            }
        }


          #region   旧的登录方式
          //try
            //{

            //    SqlConnection conn = new SqlConnection(Dbconnect.s1);
            //    conn.Open();
            //    SqlCommand sc = new SqlCommand("select usepwd,miyao from employee where empcode=@usename", conn);
            //    sc.Parameters.AddWithValue("@usename", comboBox1.Text);

            //    SqlDataReader sdr = sc.ExecuteReader();
            //    sdr.Read();
            //    {
            //        s1 = sdr.GetString(0);
            //        s2 = sdr.GetString(1);
            //    }
            //    sdr.Close();
            //    string s3 = jm(s1, s2);
            //    if (s3 == textBox1.Text)
            //    {


            //        Mainform f2 = new Mainform();
            //        f2.ShowDialog();
            //        textBox1.Text = "";
            //        this.Close();
            //    }
            //    else
            //    {
            //        textBox1.Text = "";
            //        label3.Visible = true;
            //    }
            //}
            //catch (Exception e1)
            //{  }
            #endregion
        
    }
}